//
//  HQOfflineTableViewController.swift
//  TodayNews
//
//  Created by 郝庆 on 16/8/22.
//  Copyright © 2016年 haoqing. All rights reserved.
//

import UIKit

let offlineCellID = "HQOfflineCell"

class HQOfflineTableViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 设置UI界面
        setupUI()
    }
    
    /// 设置UI界面
    private func setupUI() {
    
        title = "离线下载"
        // 下载按钮
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "下载", style: .Plain, target: self, action: #selector(downloadClicked))
        // 注册
        let nib = UINib(nibName: String(HQOfflineCell), bundle: nil)
        tableView.registerNib(nib, forCellReuseIdentifier: offlineCellID)
        
        
    }
    
    // 点击事件
    @objc private func downloadClicked() {
        print(#function)
    }
}

// MARK: - UITableViewDataSource
extension HQOfflineTableViewController {
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 50
    }
    
    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(offlineCellID) as! HQOfflineCell
        
        cell.nameLabel?.text = "测试数据 + \(indexPath.row)"
        
        cell.selectedImageView.image = UIImage(named: "air_download_option_20x20_")
        cell.selectedImageView.highlightedImage = UIImage(named: "air_download_option_press_20x20_")
        
        return cell
        
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        let cell = tableView.cellForRowAtIndexPath(indexPath) as! HQOfflineCell
        cell.selectedImageView.highlighted = true
    }
}
